<template>
	<view class="box">
		<view class="banner">
			<image src="https://s1.ax1x.com/2022/12/02/zBCHb9.png" mode="widthFix"></image>
		</view>
		<view class="add">
			<input type="text" placeholder="请输入车牌号" v-model="carno">
		</view>
		<button class="btn" @click="addCart">添加</button>
	</view>
</template>

<script>
	import {addcar} from '../../../utils/api.js'
	export default {
		data() {
			return {
				checked:false,
				carno:''
			}
		},
		methods: {
			async addCart(){
				if(!this.isCart){
					uni.showToast({
						title:'车牌格式不正确',
						icon:'error',
						duration:2000
					})
					return false
				}
				let data={
					id:0,
					carno:this.carno
				}
				let res=await addcar(data)
				if(res.errCode===10000){
					uni.showToast({
						title:'添加成功',
						icon:'success',
						duration:2000
					})
					uni.navigateTo({
						url:'/pages/mine/cat/cat'
					})
				}
			}
		},
		computed:{
			isCart(){
				let reg=/^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/
				return reg.test(this.carno)
			}
		}
	}
</script>

<style lang="less" scoped>
	.box {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		

		.banner image {
			width: 100%;
		}

		.add{
			width: 100%;
			input{
				width: 635rpx;
				height: 90rpx;
				margin: 0 auto;
				background-color: #f6f6f6;
				font-size: 24rpx;
				padding-left: 40rpx;
				box-sizing: border-box;
				margin-top: 100rpx;
			}
		}
		.btn{
			width: 635rpx;
			height: 95rpx;
			margin: 0 auto;
			border-radius: 45rpx;
			border: 0;
			background-color: #1f8fff;
			color: #fff;
			margin-top: 120rpx;
		}
	}
</style>
